/*
ID:luongho3
LANG:C++
TASK:concom
*/
#include <iostream>
#include <fstream>
#include <stack>
using namespace std;
ifstream fin("concom.in");
ofstream fout("concom.out");
typedef stack<int> iStack;
#define MAXCOM 101
int nedge, m[MAXCOM][MAXCOM],label[MAXCOM][MAXCOM];
iStack stk[MAXCOM];
int main() {
    int i,j,k;
    fin >> nedge;
    for (i=1;i<MAXCOM;++i) {
        for (j=1;j<MAXCOM;++j) {
            if (i==j) m[i][j] = 100;
            else m[i][j] = 0;
        }
    }
    for (i=1;i<=nedge;++i) {
        fin >> j >> k;
        fin >> m[j][k];
    }
    for (i=1;i<MAXCOM;++i) {
        for (j=1;j<MAXCOM;++j) {
            if (i!=j) {
               if (m[i][j] > 50) {
                  stk[i].push(j);
                  label[i][j] = 1;
               }
            }
        }
    }
    for (i=1;i<MAXCOM;++i) {
        while (!stk[i].empty()) {
              j = stk[i].top();
              stk[i].pop();
              for (k=1;k<MAXCOM;++k) {
                  if (k!=i && k!=j && m[j][k] > 0) {
                     m[i][k] += m[j][k];
                     if (m[i][k] > 50) {
                        if (label[i][k]!=1) {
                           stk[i].push(k);
                           label[i][k] = 1;
                        }
                     }
                  }
              }
        }
    }
    for (i=1;i<MAXCOM;++i) {
        for (j=1;j<MAXCOM;++j) {
            if (i!=j) {
               if (m[i][j] > 50) {
                  fout << i << " " << j << "\n";
               }
            }
        }
    }
    return 0;
}
